package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.ISelect;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageRequest;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.BedDto;
import com.zzyl.dto.NurseRequestDto;
import com.zzyl.entity.Bed;
import com.zzyl.entity.SysUser;
import com.zzyl.enums.BasicEnum;
import com.zzyl.exception.BaseException;
import com.zzyl.mapper.BedMapper;
import com.zzyl.mapper.NurseProjectMapper;
import com.zzyl.mapper.SysUserMapper;
import com.zzyl.service.BedService;
import com.zzyl.service.NurseProjectService;
import com.zzyl.utils.ObjectUtil;
import com.zzyl.vo.BedVo;
import com.zzyl.vo.NurseVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.function.Consumer;

@Service
public class NurseProjectServiceImpl implements NurseProjectService {

    private final NurseProjectMapper nurseProjectMapper;

    public NurseProjectServiceImpl(NurseProjectMapper nurseProjectMapper, SysUserMapper sysUserMapper) {
        this.nurseProjectMapper = nurseProjectMapper;
        this.sysUserMapper = sysUserMapper;
    }

    private final SysUserMapper sysUserMapper;

    @Override
    public PageResponse<NurseVo> getNurseProjectList(NurseRequestDto dto) {
        Page<NurseVo> pageResult = PageHelper.startPage(dto.getPageNum(), dto.getPageSize()).doSelectPage(new ISelect() {
            @Override
            public void doSelect() {
                List<NurseVo> result = nurseProjectMapper.selectNurseProject(dto.getName(), dto.getStatus());
            }
        });
        List<SysUser> userResult = sysUserMapper.getUserList();
        List<NurseVo> result = pageResult.getResult();
        result.forEach(new Consumer<NurseVo>() {
            @Override
            public void accept(NurseVo nurseVo) {
                String creatorId = nurseVo.getCreateBy();
                userResult.forEach(new Consumer<SysUser>() {
                    @Override
                    public void accept(SysUser sysUser) {
                        if(creatorId.equals(sysUser.getId())){
                            nurseVo.setCreator(sysUser.getNickName());
                        }
                    }
                });
            }
        });
        return PageResponse.<NurseVo>builder()
                .records(result)
                .pages((long) pageResult.getPages())
                .total(pageResult.getTotal())
                .pageSize(pageResult.getPageSize())
                .pages((long) pageResult.getPages())
                .build();
    }

}

